<?php
/**
 * Created by PhpStorm.
 * User: longli
 * Date: 2021/08/20
 * Time: 17:17
 * @link http://www.lmterp.cn
 */

namespace app\common\behavior\swoole;

use app\common\behavior\BaseBehavior;

/**
 * swoole 消费者
 * Class Consumer
 * @package app\common\behavior\swoole
 */
class Consumer extends BaseBehavior
{
    private $isRun = false;

    /**
     * 消费者入口
     * @param $swoole
     * @date 2021/08/20
     * @author longli
     */
    public function run($swoole)
    {
        $timer = 500;
        \Swoole\Timer::tick($timer, function($timerId)
        {
            if($this->isRun) return;
            $this->isRun = true;
            while(true)
            {
                $message = null;
                // @todo 处理消息队列
                if(empty($message))
                {
                    $this->isRun = false;
                    break;
                }
            }
        });
    }
}